package com.tl.mq.rabbit_mq.config;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SendConfig {

    // 直接声明队列
    @Bean
    public Queue queue(){
        return new Queue("img");
    }


    // 使用Topic交换机，依据规则绑定队列,with
    @Bean(name = "img_topic")
    public  Queue queueTopic(){
        return new Queue("img_topic");
    }

    @Bean(name = "exchange_topic")
    public TopicExchange topicExchange(){
        return new TopicExchange("exchange_topic");
    }

    @Bean
    Binding exchangeMes(@Qualifier("img_topic") Queue queueTopic, TopicExchange topicExchange){
        return BindingBuilder.bind(queueTopic).to(topicExchange).with("*");
    }

    // 使用fanout交换机,依据绑定分发消息
    @Bean(name = "img_fanout")
    public Queue queueFanout(){
        return new Queue("img_fanout");
    }

    @Bean(name = "exchange_fanout")
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("exchange_fanout");
    }

    @Bean
    Binding exchangeMsgFanout(@Qualifier("img_fanout") Queue queueFanout, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queueFanout).to(fanoutExchange);
    }





}
